﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//................
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//.................
namespace QLKTX1._0.DAO
{
    class TonGiaoDAO
    {
        public static List<TonGiaoDTO> dsTonGiao()
        {
            List<TonGiaoDTO> dsTonGiao = new List<TonGiaoDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM TonGiao order by (tenTonGiao) asc");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TonGiaoDTO tg = new TonGiaoDTO();

               tg.MaTonGiao  = Int32.Parse(dt.Rows[i]["maTonGiao"].ToString());
               tg.TenTonGiao  = dt.Rows[i]["tenTonGiao"].ToString();

               dsTonGiao.Add(tg);
            }
            return dsTonGiao;
        }
        //ham them 
        public static bool themTonGiao(TonGiaoDTO tg)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("INSERT INTO TonGiao(tenTonGiao) VALUES('" + tg.TenTonGiao  + "')");
        }
        //ham xoa 
        public static bool xoaTonGiao(TonGiaoDTO tg)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("DELETE FROM TonGiao WHERE maTonGiao='" + tg.MaTonGiao + "' ");
        }
        //ham cap nhat 
        public static bool capNhatTonGiao(TonGiaoDTO tg)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("UPDATE TonGiao set tenTonGiao='" + tg.TenTonGiao + "' WHERE maTonGiao='" + tg.MaTonGiao + "' ");
        }

    }
}
